package com.itheima.health.job;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.service.CleanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Wu Ji  on 2020/12/6 15:09
 */
@Component
@Slf4j
public class ChangeOrderStatus {
    @Reference
    private CleanService cleanService;
    //@Scheduled(cron = 0 0 12 * * ?)  //实战用
    //测试用
    @Scheduled(initialDelay = 5000,fixedDelay = 180000)
    public void ChangeOrderStates()  {
        String today,yesterday;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        Calendar cal_1 = Calendar.getInstance();
        cal_1.setTime(new Date());
        cal_1.add(Calendar.DATE, -1);
        yesterday=format.format(cal_1.getTime());
        //System.out.println(yesterday);

        Calendar cal_2=Calendar.getInstance();
        today = format.format(cal_2.getTime());
        //System.out.println(today);
        //测试使用需要指定日期
        cleanService.ChangeOrderStates("2020-04-28","2020-04-29");
        //实际需求需要使用
        //cleanService.ChangeOrderStates(yesterday,today);
        log.info("执行完了定时清理任务");



    }







}
